﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="FixedWordLoadSet.aspx.cs" Inherits="Basic4Net.OAWeb.Module_Base.FixedWordLoadSet" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>岗位固定工作量</title>
    <link type="text/css" rel="stylesheet" href="../App_Themes/ui-lightness/main.css" />
    <script type="text/javascript" src="../Scripts/jquery-1.4.1.js"></script>
    <script type="text/javascript" src="../Scripts/Common.js"></script>    
    <%--<script type="text/javascript" src="../Scripts/js/jsUtil.js"></script>--%>

    <script>

        var re = /^[0-9]+.?[0-9]*$/; //验证正数
        var delArr = new Array();  

       

        //关闭遮罩层
        function CloseMask(formId) {
            ClosePopForm(formId, true);
            hideMask();
        }
        //---------------------------------------------------------------------------------其他 
        


        //编辑状态
        function modi(obj) {
            
            if (obj.readOnly == true) {
                //   obj.parentElement.style.textAlign = 'center';
                obj.style.textAlign = 'left';
                obj.style.border = 'solid #a5a5a5 1px;';
                obj.readOnly = false;
                obj.select();
                updateActivate = 1;
            }
        }


        //非编辑状态
        function unModi(obj, align) {
            if (obj.readOnly == false) {
                obj.parentElement.style.textAlign = align;
                obj.style.textAlign = align;
                obj.style.border = 'solid #ffffff 1px;';
                obj.readOnly = true;
                updateActivate = 0;
            }
        }


        //选中行高亮
        function SetHightLight(obj) {
            if (obj != null)
                obj.style.backgroundColor = "#fffccf";

            var table = document.getElementById('table');
            for (var i = 0; i < table.rows.length; i++) {
                var row = table.rows[i];
                if (row != null && row.rowIndex != obj.rowIndex) {
                    row.style.backgroundColor = "#ffffff";
                }
            }
        } 


        function FilterCount() {
            var value = event.srcElement.value;
            var table = document.getElementById('table');
            var rowIndex = event.srcElement.parentElement.parentElement.rowIndex;
            var row = table.rows[rowIndex];
            if (value == 1) {
                row.cells[2].all[0].style.display = "none";
                //    row.cells[3].all[0].style.display = "none"; 
            }
            else {
                row.cells[2].all[0].style.display = "block";
                //    row.cells[3].all[0].style.display  = "block"; 
            }
        }

        //------------------------------------------------------------------------------------添加
        //-----------弹出添加类型遮罩层
        function ShowAddWindow() {
            document.getElementById("txtTypeName").value = "";
            ShowPopForm("popTable", "formTitle", "添加类型");
            showMask();
            document.getElementById('txtTypeName').focus();
        } 

        function AddRow() { 
            var table = document.getElementById('table');
            document.getElementById('txtPostName').value = ""; //清空分值名
            ShowPopForm("popTable", "formTitle", "添加");
            showMask(); 
        }

        function Add() {
            if (document.getElementById('table') != null) {
                var table = document.getElementById('table');
                var postName = document.getElementById('txtPostName').value.Trim();
                var converNum = document.getElementById('txtConverNum').value.Trim();  
                if (postName.length == 0) {
                    showNoticMsg('txtPostName', '请先确定要添加的岗位名', -120, 10); 
                    return;
                }
                if (converNum.length == 0) {
                    showNoticMsg('txtConverNum', '请先确定要添加的折算节数', -120, 10);
                    return;
                }
                 
                PageMethods.ValidateItemName(postName, function (succ) {
                    if (succ > 0) {
                        showNoticMsg('txtPostName', '岗位名重复，请重新输入', -80, 10);
                        return;
                    }
                    else {
                        if (converNum != null && converNum.length > 0) {
                            if (converNum > 0) {
                                if (!re.test(converNum)) {
                                    showNoticMsg('txtConverNum', "非法输入！请输入数字(例:1,0.02)", -80, 10);
                                    document.getElementById('txtConverNum').focus();
                                    return;
                                }
                            }
                            else {
                                showNoticMsg("txtConverNum", "非法输入，请输入大于0的数字", -80, 10);
                                document.getElementById("txtConverNum").focus();
                                return;
                            }
                        }

                        PageMethods.Insert(postName, converNum, function (succ) {
                            if (succ > 0) {
                                showMassgeBox("提示", "添加成功", 1, null);
                                CloseMask('popTable');
                                Bind();
                            }
                        }, function (err) {
                            showMassgeBox("提示", "添加失败", 1, null);
                        }); 
                    }
                }, function (err) {
                    showMassgeBox("提示", "验证失败", 1, null);
                });  
            }
        } 

        //验证指标名是否重复
        function ValidateItemName(postName) {
            var bValidate = 1;
            PageMethods.ValidateItemName(postName, function (succ) { 
                    bValidate = succ; 
            }, function (err) {
                showMassgeBox("提示", "验证失败", 1, null);
            }); 
            return bValidate;
        }

        //--------------------------------------------------------------------------------------验证及修改

        function UpdateInfo(row) {
            if (row != null) {
                var rid = row.itemid;
                var postName = "";
                var convertNum = "";
                if (row.cells[0].all != null && row.cells[0].all.length > 0) {
                    postName = row.cells[0].all[0].value;

                    if (row.cells[0].all[0].value != row.cells[0].all[0].oldvalue) {
                        PageMethods.ValidateItemName(postName, function (succ) {
                            if (succ > 0) {
                                showNoticMsg(row.cells[0].all[0].id, '岗位名重复，请重新输入', -80, 10);
                                row.cells[0].all[0].value = row.cells[0].all[0].oldvalue;
                                return;
                            }
                            else {
                                if (row.cells[1].all != null && row.cells[1].all.length > 0) {
                                    convertNum = row.cells[1].all[0].value;
                                }
                                PageMethods.UpdateInfo(rid, postName, convertNum, function (succ) {
                                    if (succ > 0) {
                                        Bind();
                                    }
                                }, function (err) {
                                    showMassgeBox("提示", "验证失败", 1, null);
                                });
                            }
                        }, function (err) {
                            showMassgeBox("提示", "验证失败", 1, null);
                        });
                    }
                    else {
                        if (row.cells[1].all != null && row.cells[1].all.length > 0) {
                            convertNum = row.cells[1].all[0].value;
                        }
                        PageMethods.UpdateInfo(rid, postName, convertNum, function (succ) {
                            if (succ > 0) {
                                Bind();
                            }
                        }, function (err) {
                            showMassgeBox("提示", "验证失败", 1, null);
                        });
                    }
                } 
            }
        }

        function optionSettingScore(obj) {
            s = true;

            var id = obj.parentElement.parentElement.id;
            var value = obj.value;

            if (value.search(/^(-|\+)?\d+(\.\d+)?$/) == -1) {

                if (value.length > 0 && value.charAt(value.length - 1) == ".") {
                    value = value.substr(0, value.length - 1);
                    if (value.search(/^(-|\+)?\d+(\.\d+)?$/) == -1) {
                        obj.setAttribute("value", obj.getAttribute("oldvalue"));
                        return;
                    }
                    else {
                        if (CheckCh(value)) {
                            obj.setAttribute("value", value);
                            obj.setAttribute("oldvalue", value);
                        }
                        else {
                            obj.setAttribute("oldvalue", value);
                        }
                    }
                }
                else {
                    if (value.length == 0 || (/\D/.test(value))) {
                        obj.setAttribute("value", obj.getAttribute("oldvalue"));
                        return;
                    }
                    else {
                        obj.setAttribute("value", value);
                        obj.setAttribute("oldvalue", value);
                    }
                } 
            }
            else {
                obj.setAttribute("oldvalue", value);
            }

            unModi(obj, 'right');
            UpdateInfo(obj.parentElement.parentElement);
        }

        function CheckCh(avalue) {
            for (n = 0; n < avalue.length; n++) {
                if (avalue[n] > 128)//   中文字符
                {
                    return false;
                }
            }
            return true;
        }

        function optionSettingProject(obj) {
            s = true;
            //var id = obj.parentElement.parentElement.id;
            var value = obj.value;

            if (value.length == 0) {
                obj.setAttribute("value", obj.getAttribute("oldvalue"));
                value = obj.value;
                return;
            }
            else {
                obj.value = value;
                value = obj.value;
            }

            unModi(obj, 'left');

            UpdateInfo(obj.parentElement.parentElement);
        }


        //----------------------------------------------------------------------------------------删除 
        //弹出删除窗口  
        function ShowDelWindow(row) { 
            showConfirmBox("删除", "确定删除此职务?", DelPostInfo, row);
        }

        function DelPostInfo(row) {
            var table = document.getElementById('table');
            table.deleteRow(row.rowIndex);
            if (row.itemid != null) {
                PageMethods.DeleteByID(row.itemid, function (succ) { 
                    if (succ > 0) {
                        showMassgeBox("提示", "删除成功", 1, null);
                        Bind();
                    }

                }, function (err) {
                    showMassgeBox("提示", "验证失败", 1, null);
                });  
            }
        }


        function Bind() {
            delArr = new Array();
            document.getElementById('btnItemBind').click();
        }



    </script>
</head>
<body>
    <div style="overflow-y: auto; overflow-x: none; height: 98%;">
        <form id="form1" runat="server">
            <div class="mainWarp">
                <div class="pageBody" style="height: 96%;">
                    <asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true">
                    </asp:ScriptManager>  
                        
                    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
                        <ContentTemplate>
                        <ul class="butList">
                            <li>
                                <input type="button" value="新增" class="commonBut" id="btnAddItem" onclick="AddRow();" />
                            </li>
                        </ul>  
                                
                        <div style="overflow-y: auto; overflow-x: none; height: 90%;">
                            <table id="table" class="useList" style="width: 50%">
                                <tr >
                                    <%--<th>参与配置</th>--%>
                                    <th style="text-align: left; padding-left: 5px;">
                                        分类名称</th>
                                    <th style="text-align: right; padding-right: 5px;">
                                        折算节数</th>  
                                    <th style="width: 10%">
                                        删除</th>
                                </tr>
                        <asp:Repeater ID="Repeater1" runat="server">    
                            <ItemTemplate> 
                                <tr itemid="<%# Eval("RID")%>"  onclick="SetHightLight(this);">
                                 <%--   <td><input type="checkbox" /></td>--%>
                                    <td>
                                        <input  onpaste="return false;"
                                        ondragenter="return false" maxlength="20" class="txtStyle" style='text-align: left;
                                        border-left: 0px; width: 98%; border-top: 0px; border-right: 0px; border-bottom: 0px;
                                        font-weight:inherit;color:#006f9f;
                                        font-style:inherit;
                                        font-size:12px; 
                                        font-family:'SimSun', Arial, Helvetica, sans-serif;'
                                        id="td<%# Eval("PostName")%>" value="<%# Eval("PostName")%>" oldvalue="<%# Eval("PostName")%>"
                                        onfocusout="optionSettingProject(this)" onclick="modi(this)" readonly /> </td>
                                    <td style=" text-align:right; padding-right:5px;">
                                        <input onkeypress="return (event.keyCode>=48&&event.keyCode<=57)||event.keyCode==46" onpaste="return false;"
                                        ondragenter="return false" maxlength="4" class="txtStyle" style='text-align: right; display:block;
                                        border-left: 0px; width: 98%; border-top: 0px; border-right: 0px; border-bottom: 0px;
                                        font-weight:inherit;color:#006f9f;
                                        font-style:inherit;
                                        font-size:12px;
                                        font-family:'SimSun', Arial, Helvetica, sans-serif;'
                                        id="Text1" value="<%# Eval("ConvertNum")%>" oldvalue="<%# Eval("ConvertNum")%>"
                                        onfocusout="optionSettingScore(this)" onclick="modi(this)" readonly />
                                    </td>
                                  
                                    <td><a><img src="../App_Themes/ui-lightness/images/delete_icon.gif" onclick="ShowDelWindow(this.parentElement.parentElement.parentElement);"/></a></td>
                                </tr> 
                            </ItemTemplate>
                            </asp:Repeater> 
                        </table>
                    </div>  
                </ContentTemplate>
                <Triggers>
                    <asp:AsyncPostBackTrigger ControlID="btnItemBind" EventName="Click" />
                </Triggers>
            </asp:UpdatePanel>

                <%--服务器端控件层--%>
                <div style="display:none;">
                    <asp:Button runat="server" ID="btnItemBind" onclick="btnItemBind_Click" />
                    <asp:TextBox runat="server" ID="txtHistoryId" />
                    <asp:TextBox runat="server" ID="txtTypeId" />
                </div>
                  
                     
                <%-- 添加固定工作量弹出层 --%>
                <div id="popTable" class="layoutWarp" style="display: none; width: 400px; overflow: inherit;">
                    <div class="title">
                        <span id="formTitle">添加</span> <a title="关闭" onclick="return CloseMask('popTable');">
                            关闭</a>
                    </div>
                    <table>
                        <tr><td>名称：</td><td><input type="text" id="txtPostName" maxlength="20"/></td></tr>
                        <tr><td>折算节数：</td><td><input type="text" id="txtConverNum" maxlength="20"/></td></tr>
                        <tr>
                            <td colspan="2">
                                <input type="button" id="btnOK" value="确定"class="commonBut" onclick="Add();" />
                                <input type="button" id="btnCancel" value="取消" class="commonBut" onclick="return CloseMask('popTable');"/>
                            </td>
                        </tr>
                    </table>  
                </div>  

            </div>
        </form>
    </div>
</body>
</html>


<script type="text/javascript"> 
// if(parent.canStart == true)
// {  
//    document.getElementById('btnAddItem').disabled= true ;
//    document.getElementById('btnSaveItem').disabled= true ;
//     document.getElementById('lblDepict').innerText="已经生效，不能修改！";
//     document.getElementById('btnSave').disabled = true;
//   
// }
//else
//{
//   document.getElementById('lblDepict').innerText="确认生效后，您将不能进行修改，请慎重！";
//    document.getElementById('btnAddItem').disabled= false ;
//    document.getElementById('btnSaveItem').disabled= false ;
//     document.getElementById('btnSave').disabled = false;
//} 
</script>